/**
 *模板添加、修改
 */
var form;
function formSubmit(obj){
    $("#menuName").val($("#menuId").find("option:selected").text());


    $.ajax({
        type: "post",
        data: $("#tempForm").serialize(),
        url: "/temp/setTemp",
        success: function (data) {
            if (data.code == 1) {
                layer.alert(data.msg,function(){
                    layer.closeAll();
                    load(obj);
                });
            } else {
                layer.alert(data.msg);
            }
        },
        error: function () {
            layer.alert("操作请求错误，请您稍后再试",function(){
                layer.closeAll();
                load(obj);
            });
        }
    });
}
function load(){
    window.location.href = "/temp/tempManage";
}
$(function() {
    layui.use('table', function() {
        var table = layui.table;
        form = layui.form;

        var menuId = $("#menuId_temp").val();
        $.ajax({
            url:'/permission/industryPermissionList',
            dataType:'json',
            async: false,
            success:function(data){
                var option1 = new Option("","");
                $('#menuId').append(option1);

                $.each(data,function(index,item){
                    console.log("name:"+item.name);
                    if(!menuId){
                        var option = new Option(item.name,item.id);
                    }else {
                        var option = new Option(item.name,item.id);
                        // // 如果是之前的parentId则设置选中
                        if(item.id == menuId) {
                            option.setAttribute("selected",'true');
                        }
                    }
                    $('#menuId').append(option);//往下拉菜单里添加元素
                    form.render('select'); //这个很重要
                })

            }
        });
    })

});


